/*
 * CodeSaveCommand.java
 *
 * Created on 2006년 3월 29일 (수), 오후 4:11
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.qbooks.publisher;

import java.io.File;
import java.util.*;





import javax.servlet.*;
import javax.servlet.http.*;

import com.zll.framework.conf.Configuration;
import com.zll.framework.model.HashBox;
import com.zll.framework.servlet.Command;
import com.qbooks.cms.admin.AdminDAO;
import com.qbooks.common.CommonUtil;





/**
 *
 * @author eastar
 */
public class PublisherSaveCommand implements Command
{

    public String execute(HttpServletRequest  request, HttpServletResponse response)
    throws Exception
    {
    	HashBox box = new HashBox(request);
    	
    	
    	//첨부파일
    	String docPath 	= File.separator + box.get("publisher_id") + File.separator + "doc";
    	File dir = new File(Configuration.get("dir.storage") + docPath);
    	if (!dir.exists()) {
			dir.mkdirs();
		}
    	
    	//사업자등록증 사본
		File f = box.getFile("biz_no_path");
		if (f != null) {
			File newFile = new File(dir.getPath() + File.separator + box.get("publisher_id") + "_biz" + f.getName().substring(f.getName().lastIndexOf('.')).toLowerCase());
			f.renameTo(newFile);
			box.put("biz_no_path", docPath + File.separator + newFile.getName());
		}
			
		//통신판매신고증 사본
		f = box.getFile("sales_no_path");
		if (f != null) {
			File newFile = new File(dir.getPath() + File.separator + box.get("publisher_id") + "_sales" + f.getName().substring(f.getName().lastIndexOf('.')).toLowerCase());
			f.renameTo(newFile);
			box.put("sales_no_path", docPath + File.separator + newFile.getName());
		}
		
		//통장 사본
		f = box.getFile("account_no_path");
		if (f != null) {
			File newFile = new File(dir.getPath() + File.separator + box.get("publisher_id") + "_acount" + f.getName().substring(f.getName().lastIndexOf('.')).toLowerCase());
			f.renameTo(newFile);
			box.put("account_no_path", docPath + File.separator + newFile.getName());
		}
		

		PublisherDAO dao 		= new PublisherDAO();

		dao.savePublisher(box);


		HashMap result		= new HashMap();
		result.put("result", 	"true");
		result.put("target",	box.target);
		result.put("action",	"/publisher/publisherInfo.jsp");
		

    	request.setAttribute("result", result);


    	return "/common/move_view.jsp";
    }
}
